<% // Copyright 2008 Carnegie Mellon University
// Licensed under the Apache License, Version 2.0 (the "License"); 
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//  
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, 
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License. %>
<%@ page language="java" contentType="text/javascript; charset=UTF-8" %>
<%@ page pageEncoding="UTF-8" %>

<% 
request.setCharacterEncoding("UTF-8");

/**
String taskName = (String)session.getAttribute("taskName");
**/
int userId = (Integer)session.getAttribute("userId");
String lang = (String)session.getAttribute("trgLang");

//HACK!! 
String taskName = "testing";
%>

var simpleEncoding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
 
function simpleEncode(valueArray,maxValue) {

  var chartData = [''];
  for (var i = 0; i < valueArray.length; i++) {
       var currentValue = valueArray[i];
       if (!isNaN(currentValue) && currentValue >= 0) {
         chartData.push(simpleEncoding.charAt(Math.round((simpleEncoding.length-1) * currentValue / maxValue)));
       } else {
         chartData.push('_');
       }
  }
  return chartData.join('');
}

var progress = eval("(<%//Json.getTaskProgress( taskName, lang, userId, 80 , 80+10 )%>)"); 

function drawProgress( task ) {
    var v1;
    var v2;
    var lang = "<%=lang%>";
     var title = "Progress of \""+lang+"\" <%=taskName%> data set";
    var maxValue = 80;
  
    if ( task == "td" ) {
        v1 = progress.<%=lang%>.td_done;
        v2 = progress.<%=lang%>.td_todo;
    } else if ( task == "ne" ) {
        v1 = progress.<%=lang%>.ne_done;
        v2 = progress.<%=lang%>.ne_todo;
  } else if ( task == "nv" ) {
        v1 = progress.<%=lang%>.nv_done;
        v2 = progress.<%=lang%>.nv_todo;
    }
    document.write( "<img src='http://chart.apis.google.com/chart?chs=270x90&cht=bhs&chd=s:"+simpleEncode(v1,maxValue)+","+simpleEncode(v2,maxValue)+"&chco=66FF66,CCCCCCCC&chtt="+title+"&chxt=x,y&chbh=8,4&chxl=0:|0|20|40|60|80|1:|EVE|REL|BIO|DEF' style='padding:5px;margin-top:10px;margin-bottom:10px;border: dotted 1px #fff' title='"+title+"'>" );
}